package com.sunlands.qdcy.tongzhuo.web;

import com.sunlands.qdcy.tongzhuo.common.annotation.AutoLog;
import com.sunlands.qdcy.tongzhuo.constant.CommonResultMessage;
import com.sunlands.qdcy.tongzhuo.exception.SensitiveException;
import com.sunlands.qdcy.tongzhuo.feign.SocketClient;
import com.sunlands.qdcy.tongzhuo.model.DiaryDO;
import com.sunlands.qdcy.tongzhuo.model.DiaryTopicDO;
import com.sunlands.qdcy.tongzhuo.service.DiaryService;
import com.sunlands.qdcy.tongzhuo.service.UserDiaryTopicService;
import com.sunlands.qdcy.tongzhuo.util.QRCodeTools;
import com.sunlands.qdcy.tongzhuo.vo.*;
import io.swagger.annotations.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.sunlands.qdcy.tongzhuo.common.annotation.AutoLog.Level.DEBUG;
import static com.sunlands.qdcy.tongzhuo.constant.CommonResultMessage.CON_SENSITIVE;

/**
 * @author shixiaopeng
 */

@Slf4j
@Api(tags = "3、测试")
@RestController
@RequestMapping("/test")
@EnableScheduling
public class TestController extends BaseController {

//    @Autowired
//    private DiaryService diaryService;
//
////    @AutoLog
//    @ApiOperation(value = "删除带二维码的日记")
//    @GetMapping("/test")
//    @Scheduled(cron = "0/60 * * * * ?")
//    public BusinessResult<String> saveHistoryTopic() {
//        Pageable pageable = new PageRequest(0, 10000, new Sort(Sort.Direction.DESC, "createTime"));
//        Page<DiaryDO> page = diaryService.find2DayDiary(pageable);
//        log.info("查询出日记共 {} 条，", page.getTotalElements());
//        int i = 0;
//        List<DiaryDO> content = page.getContent();
//        List<DiaryDO> list = new ArrayList<>();
//        for (DiaryDO diaryDO : content) {
//
//            if(diaryDO.getCreateType().equals(DiaryDO.CreateTypeEnums.FORWARD.type)){
//                Long rootId = diaryDO.getRootId();
//                DiaryDO di = diaryService.findById(rootId);
//                String imgUrls2 = di.getImgUrls();
//                if (check(imgUrls2)) {
//                    i++;
//                    log.info("转发 检测到违规 diary = {}", diaryDO);
//                    list.add(diaryDO);
//                }
//            }
//            String imgUrls = diaryDO.getImgUrls();
//
//            if (check(imgUrls)) {
//                i++;
//                log.info("检测到违规 diary = {}", diaryDO);
//                list.add(diaryDO);
//            }
//        }
//
//        log.info("一共需要删除的日记数量 size = {}", list.size());
//        list.forEach(diaryDO -> {
//            diaryDO.setCreateType(DiaryDO.CreateTypeEnums.DELETE.type);
//            diaryService.save(diaryDO);
//        });
//        return BusinessResult.createSuccessInstance("success");
//    }
//
//    private boolean check(String imgUrls) {
//        if (StringUtils.isNotBlank(imgUrls)) {
//            List<String> imgList = Arrays.asList(imgUrls.split(","));
//            for (String img : imgList) {
//                String path = QRCodeTools.deEncodeByPath(img);
//                if (StringUtils.isNotBlank(path)) {
//                    for(String key :kyeWords){
//                        if (path.contains(key)) {
//                            return true;
//                        }
//                    }
//
//                }
//            }
//        }
//        return false;
//    }
//
//
//    public List<String> kyeWords = Arrays.asList("qq","wechat", "weixin","dingtalk");

}
